/** @file InputManager.h
    @class InputManager
    @brief Singleton class for managing input
*/
#include "stdafx.h"

#ifndef _InputManager_h_
#define _InputManager_h_

#include "InputObserver.h"
#include <list>
#include <OISEvents.h>
#include <OISInputManager.h>
#include <OISKeyboard.h>
#include <OISMouse.h>

class InputManager : public OIS::KeyListener, public OIS::MouseListener, public Ogre::WindowEventListener
{
public:
	/**
	* @brief Get singleton instance
	*/
	static InputManager* getInstance();
	
	/**
	* @brief Add a new InputObserver to listen for input
	*/
	void registerObserver(InputObserver* observer);
	
	/**
	* @brief Remove InputObserver listening for input
	*/
	void unregisterObserver(InputObserver* observer);
	
	/**
	* @brief Initialize InputManager
	*/
	void initialize(Ogre::RenderWindow* window);
	
	/**
	* @brief Function that is called when a key is pressed
	*/
	virtual bool keyPressed(const OIS::KeyEvent &arg);
	
	/**
	* @brief Function that is called when a key is released
	*/
	virtual bool keyReleased(const OIS::KeyEvent &arg);
	
	/**
	* @brief Function that is called when the mouse is moved
	*/
	virtual bool mouseMoved( const OIS::MouseEvent &arg );
	
	/**
	* @brief Function that is called when a mousebutton is pressed
	*/
	virtual bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
	
	/**
	* @brief Function that is called when a mousebutton is released
	*/
	virtual bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
	
	/**
	* @brief Capture the input, called each frame
	*/
	void captureInput();
	
	/**
	* @brief Get the Mouse-object
	*/
	OIS::Mouse* getMouse();
	
	/**
	* @brief Get the Keyboard-object
	*/
	OIS::Keyboard* getKeyboard();
	
	/**
	* @brief Adjust mouse clipping area
	*/
	void windowResized(Ogre::RenderWindow* rw);

	/**
	* @brief Unattach OIS before window shutdown (very important under Linux)
	*/
	void windowClosed(Ogre::RenderWindow* rw);

private:
	/**
	* @brief Private constructor
	*/
	InputManager();
	
	/**
	* @brief Private destructor
	*/
	~InputManager();


	static InputManager* instance;
	Ogre::RenderWindow* m_window;
	OIS::InputManager *m_inputManager;
	OIS::Mouse*    m_mouse;
	OIS::Keyboard* m_keyboard;

	std::list<InputObserver*>* m_observers;

	
};

#endif